package com.ak.demo;

import com.ak.demo.trigger.HelloSimpleTrigger;
import com.ak.demo.trigger.HelloTrigger;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.util.Date;

public class MyHelloSimpleTrigger {
    public static void main(String[] args) throws SchedulerException {

        Scheduler scheduler= StdSchedulerFactory.getDefaultScheduler();

        JobDetail jobDetail= JobBuilder.newJob(HelloSimpleTrigger.class)
                .withIdentity("trigger","group1")
                .usingJobData("joker","data1")
                .build();

        Date start=new Date();
        start.setTime(System.currentTimeMillis()+1000);
        Date end=new Date();

        end.setTime(System.currentTimeMillis()+10000);
        Trigger trigger=TriggerBuilder.newTrigger()
                .withIdentity("trigger","group1")
                .startAt(start)
                .endAt(end)
                // 启动时间1 秒后
                // 结束时间10 秒后
                // 期间运行每隔 3秒运行一次
                .withSchedule(SimpleScheduleBuilder
                        .simpleSchedule()
                        .withIntervalInSeconds(3)
                        .repeatForever()
                )
                .build();
        scheduler.scheduleJob(jobDetail,trigger);

        scheduler.start();
    }
}
